Ext.onReady(function(){
	var d = new Date();
	
	var fileAttachment = Ext.create('component.file.attachment',{
        objectId: '',
        imageType: "6",
        contextPath:jypath,
        colspan:2
   });

	var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
	var fromPanelInfo = Ext.create("Ext.form.FormPanel", {
		autoWidth: true,
		autoHeight: true,
		fieldDefaults: {
            labelWidth: 120,
            labelAlign: "right",
            margin: "0 0 10 0"
        },
		items: [
			{
				xtype: "fieldcontainer", layout: "hbox",
				items: [
					{xtype: "displayfield", name: "businessType", fieldLabel: "业务类型", widht: 400}
					
				]
			},{
				xtype: "fieldcontainer", layout: "hbox",
				items: [
				{xtype: "displayfield", name: "customerName", fieldLabel: "客户姓名", width: 400}
				]
			},
			{
				xtype: "fieldcontainer", layout: "hbox",
				items: [
					
					{xtype: "displayfield", name: "receivables", fieldLabel: "已收金额", width: 400, renderer: Ext.util.Format.numberRenderer('0,000.00')},
					{
						 xtype:'displayfield',
				    	 fieldLabel:'认购日期',
				    	 id:'contractDate'
					}
				]
			},
		
			{
				xtype: "fieldcontainer", layout: "hbox",
				items: [
					{xtype: "displayfield", name: "roomCombox", fieldLabel: "原楼盘名称及房号", width: 400},
					{xtype: "displayfield", name: "calculateArea", fieldLabel: "原计价面积", width: 400, renderer: Ext.util.Format.numberRenderer('0,000.00')}
				]
			},
			{
				xtype: "fieldcontainer", layout: "hbox",
				items: [
					{xtype: "displayfield", name: "conversionPrice", fieldLabel: "原房屋单价", width: 400, renderer: Ext.util.Format.numberRenderer('0,000.00')},
					{xtype: "displayfield", name: "lumpsumPrice", fieldLabel: "原折前总价", width: 400, renderer: Ext.util.Format.numberRenderer('0,000.00')}
				]
			},
			{
				xtype: "fieldcontainer", layout: "hbox",
				items: [
					{xtype: "displayfield", fieldLabel: "原业务明细", 
						value: 
			                "<a href='javascript:parent.openMenu(\"0\",\""+abnormaId+"\",\"\",\"认购详情\",\"/customer/subscribe/toView?id="+abnormaId+"&returnUrl=,marketing,pin,index\")' style='cursor:pointer'>点击查看认购明细</a>"

							/*"<a href='"+jypath+"/customer/subscribe/toView?id="+abnormaId+"&processFlag=processHistoryShow&returnUrl=,marketing,businessAbnorma,abnormaBusiness(abnormaId)"+abnormaId+"'>点击查看认购明细</a>"*/
						},
					{
						xtype:'button',
						text: "选择房间",
					    allowDepress: true,   
					    enableToggle: true, 
					    handler:function(){   
					    	var selectWindow=Ext.create('component.estate.selectWindow',{
	           		 	        callbackFun: function (record) {
	           		 	          var result=Ext.JSON.decode(record);
	           		 	          var form=fromPanelInfo.getForm();
	           		 	          form.setValues(result);
		       		 	          form.findField("newRoomId").setValue(result.id);
	           		 	        },
           		 	            customerId:customerId,
           		 	            rStatus:'true'
	           		 	    });
	           		 	    selectWindow.show();  
		                } 
				} 
					]
				
			},
			{xtype: "textfield", name: "businessId", hidden: true, value: abnormaId},
			{xtype: "textfield", name: "newRoomId", hidden: true},
			{
				xtype: "fieldcontainer", layout: "hbox",
				items: [
					{xtype: "displayfield", name: "combinedName", fieldLabel: "所换楼盘名称及房号", width: 400},
					{xtype: "textfield", name: "billingArea", fieldLabel: "所换计价面积", width: 400, readOnly: true, renderer: Ext.util.Format.numberRenderer('0,000.00')}
				]
			},
			{
				xtype: "fieldcontainer", layout: "hbox",
				items: [
					{xtype: "textfield", name: "unitPrice", fieldLabel: "所换房屋单价", width: 400, readOnly: true, renderer: Ext.util.Format.numberRenderer('0,000.00')},
					{xtype: "textfield", name: "totalPrice", fieldLabel: "所换折前总价", width: 400, readOnly: true, renderer: Ext.util.Format.numberRenderer('0,000.00')}
				]
			},
			{
				xtype : 'textarea', fieldLabel : '换房原因',id:'reason',width: 800, maxLength: 255,
				name: "remark", allowBlank:false, blankText:'不能为空'
			},
			{
				xtype: "fieldcontainer", layout: "hbox",
				items: [
					{xtype: "displayfield", value :userName, fieldLabel: "经纪人", width: 400},
					{xtype: "displayfield", name: "applyDate", fieldLabel: "申请日期", width: 400,value: str
					}
				]
			},fileAttachment
		]
	});
	
	   fromPanelInfo.getForm().load({
			url:jypath+'/marketing/businessAbnorma/abnormaBusinessById',
			params:{'abnormaId':abnormaId},
			success:function(form, action){
				var obj = action.result.data;
				Ext.getCmp("contractDate").setValue(Ext.Date.format(new Date(obj.contractDate),'Y-m-d'));
				 var form=fromPanelInfo.getForm();
				form.findField("remark").setValue("");
				form.findField("applyDate").setValue(str);
			},   
			failure: function(form, action) {
		        Ext.Msg.alert("加载失败", action.result.errorMessage);
		    }

		});
	
	var changeRecordPanel = Ext.create("Ext.panel.Panel", {
		renderTo:Ext.getBody(),
		title: "认购换房",
		items: [fromPanelInfo],
		bbar : [
			{
				xtype: "button",
				text : "返回",
				id: "btn_back",
				name: "btn_back",
				icon : jypath + '/resources/ExtJSicons/shape_move_backwards.png',
				listeners: {
					click: function(){
						  var tabKey = "abs_"+abnormaId;
						  parent.TabControlRemove(tabKey);
					}
				}
			},{
				xtype: "button",
				text : "提交审核",
				id: "btn_save",
				name: "btn_save",
				icon : jypath + '/resources/ExtJSicons/database_add.png',
				listeners:{
					click: function(){

	                	var form = fromPanelInfo.getForm();
	                	if(form.isValid()){
	                		var fileUrlArr = fileAttachment.getFileArrs();
	                		var params={
		                			'businessId':abnormaId,
		                			'newRoomId':form.findField("newRoomId").getValue(),
		                			'bfdTotalPrice':form.findField("totalPrice").getValue(),
		                			'calculateArea':form.findField("billingArea").getValue(),
		                			'bfdUnitPrice':form.findField("unitPrice").getValue(),
		                			'remark':Ext.getCmp("reason").getValue(),
		                			fileUrlArr:fileUrlArr,
		                			imageType: "6",
		                			'token':token
		                	};
	                		Ext.Msg.wait("正在处理，请稍等...","");
	                		Ext.Ajax.request({
		                		url:jypath+'/marketing/businessAbnorma/addChangeHouse',
		                		params:params,
		                		callback: function (options, success, response) {
		                			 Ext.Msg.hide();
		                			 var obj = JSON.parse(response.responseText);
		                			 if(obj.res=="1"){
		    							 Ext.MessageBox.alert("系统提示","保存成功"); 
		    							 setTimeout(function(){
		    								 var tabKey = "abs_"+abnormaId;
			    							 parent.TabControlRemove(tabKey);
										 }, 2000);
		    						 }else{
		    							 token = obj.obj;
		    							 Ext.MessageBox.alert("系统提示",obj.resMsg); 
		    						 }
		                		}
		                	});
	                		
	                	}
					}
				}
			}
		]
	});
});